package com.itheima.sh.controller;

import com.itheima.sh.feign.UserFeignApi;
import com.itheima.sh.pojo.User;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author YYP
 * @date 2020/12/20
 */
@RestController
@RequestMapping("feign")
public class FeignController {

    //降级写在这里，耦合太强，写在service_api

    @Autowired
    UserFeignApi userFeignApi;

    @GetMapping("{id}")
    //使用HystixCommond来指定降级的方法。
    //@HystrixCommand(fallbackMethod = "queryByIdFallback")
    public User queryById(@PathVariable("id") String id){
        return userFeignApi.queryById(id);
    }

/*
    //降级方法
    public User queryByIdFallback(@PathVariable("id") String id){
        User user = new User();
        user.setUsername(id);
        user.setName("暂停服务");
        return user;
    }*/


}
